package com.llg.controller;

import com.llg.model.FormulaVO;
import com.llg.model.response.DataResult;
import com.llg.model.response.PageResult;
import com.llg.model.response.ResponseResult;
import com.llg.service.FormulaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/formula")
@Api(value = "公式接口")
public class FormulaController {

    private final FormulaService formulaService;

    public FormulaController(FormulaService formulaService) {
        this.formulaService = formulaService;
    }

    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有公式")
    public PageResult<FormulaVO> findAll(){
        return formulaService.findAll();
    }

    //搜索并分页查询
    @PostMapping("/findList")
    @ApiOperation(value = "条件查询公式")
    public PageResult<FormulaVO> findList(Integer currentPage, Integer pageSize, @RequestBody FormulaVO formulaVo){
        return formulaService.findList(currentPage, pageSize, formulaVo);
    }

    //通过id查
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询公式")
    public DataResult<FormulaVO> findById(@PathVariable("id") Integer id){
        return formulaService.findById(id);
    }

    //增
    @PostMapping("/add")
    @ApiOperation(value = "新增公式")
    public DataResult<FormulaVO> add(@RequestBody FormulaVO formulaVo){
        return formulaService.add(formulaVo);
    }

    //删
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除公式")
    public ResponseResult delete(@PathVariable Integer id){
        return formulaService.delete(id);
    }

    //改
    @PostMapping("/update")
    @ApiOperation(value = "修改公式")
    public ResponseResult update(@RequestBody FormulaVO formulaVo) {
        return formulaService.update(formulaVo);
    }
}
